import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import Layout from '../views/layout/Layout.vue'
import UsersList from '../views/pages/UsersList'

Vue.use(VueRouter)

const routes = [
	{
		path: '/login',
		name: 'Login',
		component: () => import("../views/pages/Login.vue"),
	},
	{
		path: '/sign',
		name: 'Sign',
		component: () => import("../views/pages/users/Sign.vue"),
	},
	{
		path: '/',
		name: 'Layout',
		redirect: '/index',
		component: Layout,
		children: [
			{
				path: '/users/list',
				name: 'usersList',
				component: UsersList,
			},
			{
				path: '/index',
				name: 'index',
				component: () => import("../views/pages/Index.vue"),
			},
			{
				path: '/food/list',
				name: 'FoodList',
				component: () => import("../views/pages/food/List.vue"),
			},
			{
				path: '/food/create',
				name: 'FoodCreate',
				component: () => import("../views/pages/food/Create.vue"),
			},
			{
				path: '/order/main',
				name: 'OrderMain',
				component: () => import("@/views/pages/order/Main.vue"),
			},
			{
				path:'/order/list',
				name: 'orderList',
				component: () => import("@/views/pages/order/List.vue"),
			},
			{
				path:'/order/me',
				name: 'MyOrder',
				component: () => import("@/views/pages/order/MyOrder.vue"),
			},
		],
	},
];

const router = new VueRouter({
	routes,
	mode: "history",
});

// router.beforeEach((to, from, next) => {
// 	// 判断用户是否登录
// 	console.log('登录凭证', store.state.userInfo.id);

// 	if (store.state.userInfo.id === undefined) {
// 		console.log("未登录", to.path);

// 		if(to.path === '/login') {
// 			next();
// 			return;
// 		}
// 		// 未登录
// 		console.log("跳转到login");
// 		next("/login");
// 	}
// 	else {
// 		next();
// 	}
// });

export default router
